<?php

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

if (!function_exists('load_user_routes')) {
    function load_user_routes($api)
    {
        $api->group(
            [
                'prefix' => 'ucenter/user',
                'namespace' => 'Ucenter',
            ],
            function ($api2) {
                $api2->post('register', 'UserController@register');
                $api2->post('login', 'UserController@login');
                $api2->post('reset', 'UserController@reset');
                $api2->get('test', 'UserController@test');
            }
        );
    }
}

if (!function_exists('load_user_logged_routes')) {
    function load_user_logged_routes($api)
    {
        $api->group(
            [
                'prefix' => 'ucenter/user',
                'namespace' => 'Ucenter',
                'middleware' => ['auth.jwt'],
            ],
            function ($api2) {
                $api2->get('info', 'UserController@info');
                $api2->get('member-notice', 'UserController@memberNotice');
                $api2->get('log', 'UserController@logs');
                $api2->post('switch-notice', 'UserController@switchNotice');
                $api2->post('update-info', 'UserController@updateInfo');
                $api2->post('update-pwd', 'UserController@updatePwd');
                $api2->get('logout', 'UserController@logout');

                $api2->post('change-jypwd', 'UserController@changeJypwd');
                $api2->post('set-jypwd', 'UserController@setJypwd');
            }
        );
    }
}

$api = app('Dingo\Api\Routing\Router');
$api->version(
    'v1',
    [
        'domain' => config('app.url'),
        'prefix' => 'api',
        'namespace' => 'App\Http\Controllers\Api',
        'middleware' => ['api.throttle'],
        'limit' => 100,
        'expires' => 1,
    ],
    function ($api) {
        load_user_routes($api);
        load_user_logged_routes($api);
    },
);
require 'admin.php';
